<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Music/classes/PhpFox_ComponentApproveAlbum.class.php, $Author:  $ */



/** Component for viewing and approving unapproved albums
 * 	This component also switch On/Off approving for albums
 *   Evgeinj Grouk aka GloGen
 * @version $Id: PhpFox_ComponentApproveAlbum.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.music
 */
class PhpFox_Mod_Music_ComponentApproveAlbum extends BaseComponent
{
    function process()
    {
        $oAlbumItem    = &$this->_oModule->getItem('Album');
        /* @var $oMusicService PhpFox_Mod_Music_ItemAlbum */
        $oMusicService = &$this->_oModule->getService('Music');
        /* @var $oMusicService PhpFox_Mod_Music_ServiceMusic */
        $oTpl = &$this->_oModule->getTemplate();
        $oUrl = &App::getUrl();

        $aOut['JS'] = $oTpl->fetch('JS.html');

        $oReq = &App::getRequest();

        $aSelected = array();
        $aSelected = $oReq->getArray('sel_albums');

        if (!count($aSelected))
        {
            if ($oReq->getInt('id'))
            {
                $aSelected[] = $oReq->getInt('id');
            }
        }

        if ( $oReq->get('approve') )
        {
        	foreach ($aSelected as $iItem)
        	{
            	$iId = intval($iItem);
                $oMusicService->setAlbumApproved($iId);
            }
        }

        if ( $oReq->get('delete') )
        {
        	foreach ($aSelected as $iItem)
        	{
            	$iId = intval($iItem);
                $oMusicService->deleteAlbum($iId);
            }
        }

        $iReqPageSize = $oReq->getint('albums_page_size');
        $aPageSizes = App::getParam('Mod_Music.pager_size');
        if (isset($aPageSizes[$iReqPageSize]) and $aPageSizes[$iReqPageSize])
        {
            $iPageSize = $iReqPageSize;
            $_SESSION['album_page_size'] = $iReqPageSize;
        }
        else
        {
            if (isset( $_SESSION['album_page_size'] ))
            {
                $iPageSize = $_SESSION['album_page_size'];
            }
            else
            {
                $iPageSize = App::getParam('Mod_Music.default.admin.pagesize');
            }
        }

        App::loadClass('Sorter');
        $aFields = array('musician_name','album_title','genre_name','user_name','album_cdate',);
        $sField  = $oReq->get('fieldA', 'album_cdate');
        $sOrder  = $oReq->get('orderA', 'up');

        $oSorter = App::newObject('Sorter', $aFields, array($sField => $sOrder));
        $oSorter->sUrlFieldKey = 'fieldA';
        $oSorter->sUrlDirKey   = 'orderA';

        $iPage = $oReq->getInt('pageA', 1);
        $aCond = array();
        list($aAlbums, $iCnt) = $oMusicService->getUnapprovedAlbums($aCond, $iPage, $iPageSize, $oSorter->getOrder());

        $oConfigItem = &App::getModuleItem('Admin', 'Config');
        $oConfigItem->loadByCondition("sett.code = 'music_album_approving'");
        $bApprovalIsOff = $oConfigItem->aData['val'];

        $oPager = App::newObject('Pager', $iCnt, $iPage, $iPageSize);
        $oPager->sUrlKey = 'pageA';

        $oTpl->assign(array(
            'aAlbums'           => $aAlbums,
            'bApprovalIsOff'    => $bApprovalIsOff,
            'aAlbumsPageSize'   => $aPageSizes,
            'defAlbumsPageSize' => $iPageSize,
            'aPaging'           => $oPager->getInfo($oUrl),
            'aSorting'          => $oSorter->getSorting($oUrl),
        ));
        $aOut['main'] = $oTpl->fetch('ApproveAlbum.html');
        return $aOut;
    }
}
?>